//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.ruoyi.web.controller.app;

import com.ruoyi.live.app.service.AppAsyncService;
import com.ruoyi.live.app.service.AppService;
import com.ruoyi.live.base.domain.*;
import com.ruoyi.live.base.domain.vo.BarrageParam;
import com.ruoyi.live.base.domain.vo.TaskUserVO;
import com.ruoyi.live.tool.utils.Message;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.lang.Nullable;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import jakarta.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping({"/app"})
public class AppController {
    @Autowired
    AppService service;
    @Autowired
    AppAsyncService appAsyncService;

    public AppController() {
    }

    @ResponseBody
    @RequestMapping({"/getUserInfoByToken"})
    public Message getUserInfoByToken() {
        try {
            return this.service.getUserInfoByToken();
        } catch (Exception exception) {
            exception.printStackTrace();
            return new Message(false, "获取用户信息失败");
        }
    }

    @ResponseBody
    @RequestMapping({"/url"})
    public Message getUrl() {
        return new Message(true, "");
    }

    @ResponseBody
    @RequestMapping({"/resetExam"})
    public Message resetExam(Long id, Long leuId) {
        try {
            return this.service.doResetExam(id, leuId);
        } catch (Exception exception) {
            exception.printStackTrace();
            return new Message(false, "重置失败");
        }
    }

    @ResponseBody
    @RequestMapping({"/initApp"})
    public Map<String, Object> initApp(String version) {
        return this.service.initApp(version);
    }

    @ResponseBody
    @RequestMapping({"/isOutDate"})
    public Message isOutDate() {
        return new Message(true, "");
    }

    @ResponseBody
    @RequestMapping({"/api/examList"})
    public List<LiveExam> examList() {
        return this.service.examList();
    }

    @ResponseBody
    @RequestMapping({"/api/startExam"})
    public Message startExam(Long id) {
        try {
            this.service.startExam(id);
            return new Message(true, "");
        } catch (Exception exception) {
            exception.printStackTrace();
            return new Message(false, "开始比赛失败");
        }
    }

    @ResponseBody
    @RequestMapping({"/api/taskList"})
    public List<LiveExamTask> taskList(Long id) {
        return this.service.doTaskList(id);
    }

    @ResponseBody
    @RequestMapping({"/api/initExam"})
    public Message initExam(Long id) {
        try {
            return this.service.doStartExam(id, (Long)null);
        } catch (Exception exception) {
            exception.printStackTrace();
            return new Message(false, "操作失败");
        }
    }

    @ResponseBody
    @RequestMapping({"/api/exam/progress"})
    public LiveExamUser progress(Long id) {
        return this.service.getExamUser(id);
    }

    @ResponseBody
    @RequestMapping({"/api/product/images"})
    public List<LiveProductSource> getImages(Long id, Integer type) {
        return this.service.getImages(id, type);
    }

    @ResponseBody
    @RequestMapping({"/api/task/saveTaskDetail"})
    public Message saveTaskDetail(String banners, String title, String contents, Long taskUserId) {
        try {
            this.service.saveTaskDetail(banners, title, contents, taskUserId);
            return new Message(true, "保存成功");
        } catch (Exception exception) {
            exception.printStackTrace();
            return new Message(false, "保存失败");
        }
    }

    @ResponseBody
    @RequestMapping({"/api/task/getTaskDetail"})
    public TaskUserVO getTaskDetail(Long id) {
        return this.service.getTaskDetail(id);
    }

    @ResponseBody
    @RequestMapping({"/api/task/submitTask"})
    public Message submitTask(Long id) {
        try {
            this.service.doSubmitTask(id);
            return new Message(true, "保存成功");
        } catch (Exception exception) {
            exception.printStackTrace();
            return new Message(false, "保存失败");
        }
    }

    @ResponseBody
    @RequestMapping({"/api/task/setChannel"})
    public Message setChannel(Long taskUserId, @Nullable Long channelId, @Nullable String filename) {
        try {
            return this.service.doSetChannel(taskUserId, channelId, filename);
        } catch (Exception exception) {
            exception.printStackTrace();
            return new Message(false, "分配直播间失败");
        }
    }

    @ResponseBody
    @RequestMapping({"/api/task/setChannelWeb"})
    public Message setChannelWeb(Long taskUserId, @Nullable Long channelId) {
        try {
            return this.service.doSetChannelWeb(taskUserId, channelId);
        } catch (Exception exception) {
            exception.printStackTrace();
            return new Message(false, "分配直播间失败");
        }
    }

    @ResponseBody
    @RequestMapping({"/api/task/startLiveTask"})
    public Message startLiveTask(Long taskUserId, HttpServletRequest rquest) {
        try {
            this.service.doStartLiveTask(taskUserId, rquest);
            return new Message(true, "");
        } catch (Exception exception) {
            exception.printStackTrace();
            return new Message(false, exception.getMessage());
        }
    }

    @ResponseBody
    @RequestMapping({"/api/task/getVideoUrl"})
    public Message getVideoUrl(Long id, HttpServletRequest request) {
        return this.service.getVideoUrl(id, request);
    }

    @ResponseBody
    @RequestMapping({"/api/task/endLive"})
    public Message endLive(HttpServletRequest request, Long id, Long examUserId) {
        try {
            this.service.doEndLive(request, id, examUserId);
            return new Message(true, "");
        } catch (Exception exception) {
            exception.printStackTrace();
            return new Message(false, "直播结束失败");
        }
    }

    @ResponseBody
    @RequestMapping({"/api/task/hasVideo"})
    public Message hasVideo(Long id, HttpServletRequest request) {
        return this.service.hasVideo(id, request);
    }

    @ResponseBody
    @RequestMapping({"/api/task/getBarrage"})
    public Message getBarrage(BarrageParam param) {
        return this.service.doGetBarrage(param);
    }

    @ResponseBody
    @RequestMapping({"/api/task/getGifts"})
    public List<Map<String, Object>> getGifts() {
        return this.service.getGifts();
    }

    @ResponseBody
    @RequestMapping({"/api/task/setLastVideo"})
    public Message setLastVideo(Long id) {
        try {
            this.service.doSetLastVideo(id);
            return new Message(true, "操作成功");
        } catch (Exception exception) {
            exception.printStackTrace();
            return new Message(false, "操作失败");
        }
    }

    @ResponseBody
    @RequestMapping({"/api/task/saveTime"})
    public Message saveTime(Long id, Integer index) {
        try {
            this.service.saveTime(id, index);
        } catch (Exception exception) {
            exception.printStackTrace();
        }

        return new Message(true, "");
    }

    @ResponseBody
    @RequestMapping({"/api/task/endExam"})
    public Message endExam(Long id) {
        try {
            this.service.doEndExam(id);
            return new Message(true, "");
        } catch (Exception exception) {
            exception.printStackTrace();
            return new Message(false, "");
        }
    }

    @ResponseBody
    @RequestMapping({"/api/task/userRePass"})
    public Message userRePass(String passOld, String passNew) {
        try {
            this.service.doUserRePass(passOld, passNew);
            return new Message(true, "修改成功");
        } catch (Exception exception) {
            exception.printStackTrace();
            return new Message(false, "修改失败");
        }
    }

    @ResponseBody
    @RequestMapping({"/api/task/updateChannelUsed"})
    private Message updateChannelUsed(Long id) {
        return this.service.updateChannelUsed(id);
    }

    @ResponseBody
    @RequestMapping({"/api/task/getChannelById"})
    private LiveTaskUserChannel getChannelById(Long id) {
        return this.service.getChannelById(id);
    }

    @ResponseBody
    @RequestMapping({"/api/task/checkGoods"})
    private Message checkGoods(LiveTaskUserPut put) {
        try {
            this.service.checkGoods(put);
            return new Message(true, "上架成功");
        } catch (Exception exception) {
            exception.printStackTrace();
            return new Message(false, "上架失败");
        }
    }

    @ResponseBody
    @RequestMapping({"/api/task/getLiveContext"})
    public Message getLiveContext(Long id) {
        return this.service.getLiveContext(id);
    }

    @ResponseBody
    @RequestMapping({"/api/task/getLiveProductItems"})
    public List<LiveProduct> getLiveProductItems(Long id) {
        return this.service.getLiveProductItems(id);
    }

    @ResponseBody
    @RequestMapping({"/api/task/getReconnectChannel"})
    public Message getReconnectChannel(Long channelId) {
        return this.service.getReconnectChannel(channelId);
    }

    @ResponseBody
    @RequestMapping({"/api/task/saveChannelRecord"})
    public Message saveChannelRecord(Long channelId, String filePath) {
        try {
            this.service.saveChannelRecord(channelId, filePath);
            return new Message(true, "");
        } catch (Exception exception) {
            exception.printStackTrace();
            return new Message(false, "");
        }
    }

    @ResponseBody
    @RequestMapping({"/api/task/judgeUploadState"})
    public Message judgeUploadState(Long channelId) {
        return this.service.judgeUploadState(channelId);
    }

    @ResponseBody
    @RequestMapping({"/api/task/changeUserState"})
    public Message changeUserState() {
        try {
            this.service.doChangeUserState();
            return new Message(true, "");
        } catch (Exception exception) {
            exception.printStackTrace();
            return new Message(false, "");
        }
    }

    @ResponseBody
    @RequestMapping({"/api/task/getAllQuestions"})
    public Map<Long, List<LiveBarrage>> getAllQuestions(Long examId) {
        return this.service.getAllQuestions(examId);
    }

    @ResponseBody
    @RequestMapping({"/api/task/endLiveAsync"})
    public Message endLiveAsync(HttpServletRequest request, Long id, Long examUserId) {
        try {
            this.appAsyncService.doEndLive(request, id, examUserId);
            return new Message(true, "");
        } catch (Exception exception) {
            exception.printStackTrace();
            return new Message(false, "直播结束失败");
        }
    }

    @ResponseBody
    @RequestMapping({"/api/task/saveQuestionAsync"})
    public Message saveQuestionAsync(LiveBarrage barrage, Long taskUserId, Long channelId, Integer timeIndex) {
        try {
            this.appAsyncService.saveQuestionAsync(barrage, taskUserId, channelId, timeIndex);
            return new Message(true, "");
        } catch (Exception exception) {
            exception.printStackTrace();
            return new Message(false, "直播结束失败");
        }
    }

    @ResponseBody
    @RequestMapping({"/api/task/getRecordParams"})
    public Map<String, Integer> getRecordParams() {
        return this.service.getRecordParams();
    }
}
